package com.souku.finance.application.ui.mine;

import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.manager.RequestManager;
import com.souku.finance.application.R;
import com.souku.finance.application.base.BaseActivity;
import com.souku.finance.application.bean.UserAccBean;
import com.souku.finance.application.http.UrlConstact;
import com.souku.finance.application.http.volley.ReqListener;
import com.souku.finance.application.http.volley.Success;
import com.souku.finance.application.utils.JsonUtil;
import com.souku.finance.application.utils.MyTextUtil;
import com.souku.finance.application.utils.ParamUtil;
import com.souku.finance.application.utils.ToastUtil;
import com.souku.finance.application.widget.CircleViewHomeNopoint;

import java.util.HashMap;

/**
 * Created by Android on 2016/12/20.
 */

public class TotalActivity extends BaseActivity implements View.OnClickListener {
    protected RelativeLayout topBack;
    protected TextView topTitle;
    protected CircleViewHomeNopoint circle;
    protected TextView tvCircle;
    protected TextView tvOnlineInvest;
    protected TextView tvToReceivedInterest;
    protected TextView tvBmMoney;
    protected TextView tvBmAvailableIncome;
    protected TextView tvMoney;

    @Override
    public void internet() {
        getUserAcc();
    }

    @Override
    protected void onResume() {
        super.onResume();
        getUserAcc();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.act_total);
        initView();
//        circle.setStoke(this);
//        circle.setPrograss(0, 0, tvCircle);
        topTitle.setText("总资产");
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.top_back) {
            finish();
        }
    }

    private void initView() {
        topBack = (RelativeLayout) findViewById(R.id.top_back);
        topBack.setOnClickListener(TotalActivity.this);
        topTitle = (TextView) findViewById(R.id.top_title);
        circle = (CircleViewHomeNopoint) findViewById(R.id.circle);
        tvCircle = (TextView) findViewById(R.id.tv_circle);
        tvOnlineInvest = (TextView) findViewById(R.id.tv_online_invest);
        tvToReceivedInterest = (TextView) findViewById(R.id.tv_to_received_interest);
        tvBmMoney = (TextView) findViewById(R.id.tv_bm_money);
        tvBmAvailableIncome = (TextView) findViewById(R.id.tv_bm_available_income);
        tvMoney = (TextView) findViewById(R.id.tv_money);
    }

    private void getUserAcc() {
        HashMap<String, String> map = ParamUtil.getParams();
        RequestManager.getInstance().post(UrlConstact.USER_ACC, ParamUtil.getSing(map), new ReqListener(this, new Success() {
            @Override
            public void onSuccess(String response) {
                if (JsonUtil.getCode(response) == 1) {
                    UserAccBean bean = JsonUtil.fastBean(JsonUtil.getData(response).toString(), UserAccBean.class);
                    setData(bean);
                } else {
                    ToastUtil.show(JsonUtil.getMessage(response));
                }
            }
        }), ParamUtil.getHeaders());
    }

    private void setData(UserAccBean bean) {
        tvOnlineInvest.setText(MyTextUtil.setMoneyToElement(bean.getOnlineInvest()));
        tvToReceivedInterest.setText(MyTextUtil.setMoneyToElement(bean.getToReceivedInterest()));
        tvBmMoney.setText(MyTextUtil.setMoneyToElement(bean.getBmMoney()));
        tvBmAvailableIncome.setText(MyTextUtil.setMoneyToElement(bean.getBmAvailableIncome()));
        tvMoney.setText(MyTextUtil.setMoneyToElement(bean.getMoney()));
        tvCircle.setText(MyTextUtil.setMoneyToElement(bean.getTotalMoney()) + "元");
//        double total = Double.parseDouble(MyTextUtil.setMoneyToElement(bean.getTotalMoney()));
//        circle.setPrograss(total, total, tvCircle);
    }
}
